<?php
class UnitTestCase_Boss_Api extends UnitTestCase_Boss {

    protected $_appId;
    
    public function setUp() {
    
        $this->_appId = 'K8mQjUvV34EVSnui1qkXd5xVOeXIRONXC7kfEP33baBfqBm_kc9Hx4VA_nkfCI6y';
    
    }
    
    public function testConstruct() {
    
        $api = new Boss_Api($this->_appId);
        $this->assertEqual($api->getAppId(), $this->_appId);
        /*$request = new Boss_Request('Search term', array(
            'count' => 10,
            'start' => 10,
            'format' => 'json', // default is json
            'style' => 'raw'
        ));
        $response = $api->dispatch($request);
        if ($response->getStatus() == '200 OK') {
            $json = json_decode($response->getBody());
        }*/
    
    }
    
    public function testApiUriConst() {
    
        $this->assertEqual(Boss_Api::URI, 'http://boss.yahooapis.com');
    
    }
    
    public function testDispatchRequestAddsAppId() {
    
        $api = new Boss_Api($this->_appId);
        $request = new Boss_Request('search terms', 'web', array('format' => 'xml'));
        $response = $api->dispatch($request);
        $this->assertEqual($request->getParam('appId'), $this->_appId);
    
    }
    
    public function testDispatchReturnsResponse() {
    
        $api = new Boss_Api($this->_appId);
        $request = new Boss_Request('search terms', 'web', array('format' => 'json'));
        $response = $api->dispatch($request);
        $this->assertIsA($response, 'Boss_Response');
    
    }
    
    public function testDecodedResponse() {
    
        $api = new Boss_Api($this->_appId);
        $request = new Boss_Request('search terms', 'web', array('format' => 'json'));
        $response = $api->dispatch($request);
        $decoded = $response->getDecoded();
        $this->assertEqual($decoded->ysearchresponse->responsecode, 200);
    
    }

}